<?php
namespace app\admin\model;
use think\Model;

class Brand extends Model{
    //判断
    public function getRecommendedAttr($v,$d){
        return $d['recommended']?"是":'否';
    }
    public function getIfShowAttr($v,$d){
        return $d['if_show']?'√.jpg':'X.jpg';
    }
    //搜索器
    public function searchKeywordsAttr($q,$v,$d){
        $q->where('brand_name','like',"%".$v."%");
    }
    public function searchLogoAttr($q,$v,$d){
        if($v==1){
            $q->where('brand_logo','<>','');
        }else{
            $q->where(function ($q){
                $q->whereOr('brand_logo','=','');
                $q->whereOr('brand_logo','=',null);
            });

        }
    }
        public static function getBrandList($where=[]){
            $list=Brand::withSearch(array_keys($where),$where)->order('sort_order')->paginate([
                'list_rows'=>5,
                'query'=>$where
            ]);
            return $list;
        }
}